Loading and eye-balling a dataset
Humboldt-Universität zu Berlin
2023-04-12
## play sound if error encountered
### from: https://sejohnston.com/2015/02/24/make-r-beep-when-r-markdown-finishes-or-when-it-fails/
options(error = function(){ # Beep on error
beepr::beep(sound = "wilhelm")
Sys.sleep(2) #
}
)
## and when knitting is complete
.Last <- function() { # Beep on exiting session
beepr::beep(sound = "ping")
Sys.sleep(6) # allow to play for 6 seconds
}| alive | dead | |
|---|---|---|
| PP | Eddie Redmayne…has won | Gene Kelly…*has won |
| SF | Eddie Redmayne…will win | Gene Kelly…*will win |
Day 1
Day 2
Day 3
readr::read_csv can be read as “read_csv() function in the readr package”
package::function()
read_csv could be referring to)here package
Using the here package, we can access files relative to where our .RProj is stored.
In ‘olden times’, we had to specify the file path with something like:
Or, we’d set an absolute path as our working directory, to which all other file paths were relative
This meant that if I sent my project folder to somebody else, they wouldn’t be able to run my code because they would have to change the absolute file path to match their machine.
names() [1] "RECORDING_SESSION_LABEL" "TRIAL_INDEX"
[3] "EYE_USED" "IA_DWELL_TIME"
[5] "IA_FIRST_FIXATION_DURATION" "IA_FIRST_RUN_DWELL_TIME"
[7] "IA_FIXATION_COUNT" "IA_ID"
[9] "IA_LABEL" "IA_REGRESSION_IN"
[11] "IA_REGRESSION_IN_COUNT" "IA_REGRESSION_OUT"
[13] "IA_REGRESSION_OUT_COUNT" "IA_REGRESSION_PATH_DURATION"
[15] "KeyPress" "rt"
[17] "bio" "critical"
[19] "gender" "item_id"
[21] "list" "match"
[23] "condition" "name"
[25] "name_vital_status" "tense"
[27] "type" "yes_press"
rename()RECORDING_SESSION_LABEL corresponds to a single participantTRIAL_INDEX logged the trial numberEYE_USED logged which eye was trackedNaming conventions
It’s wise to keep variable and object names concise but informative
trial.index or trial_index
df_lifetime because it is a dataframe (df) with data from our lifetime experiment# A tibble: 6 × 28
px trial eye IA_DWELL_TIME IA_FIRST_FIXATION_DUR…¹ IA_FIRST_RUN_DWELL_T…²
<chr> <dbl> <chr> <dbl> <dbl> <dbl>
1 px3 1 RIGHT 0 0 0
2 px3 2 RIGHT 0 0 0
3 px3 3 RIGHT 0 0 0
4 px3 3 RIGHT 0 0 0
5 px3 3 RIGHT 0 0 0
6 px3 3 RIGHT 0 0 0
# ℹ abbreviated names: ¹IA_FIRST_FIXATION_DURATION, ²IA_FIRST_RUN_DWELL_TIME
# ℹ 22 more variables: IA_FIXATION_COUNT <dbl>, IA_ID <dbl>, IA_LABEL <chr>,
# IA_REGRESSION_IN <dbl>, IA_REGRESSION_IN_COUNT <dbl>,
# IA_REGRESSION_OUT <dbl>, IA_REGRESSION_OUT_COUNT <dbl>,
# IA_REGRESSION_PATH_DURATION <dbl>, KeyPress <dbl>, rt <dbl>, bio <chr>,
# critical <chr>, gender <chr>, item_id <dbl>, list <dbl>, match <chr>,
# condition <chr>, name <chr>, name_vital_status <chr>, tense <chr>, …
# A tibble: 6 × 28
px trial eye IA_DWELL_TIME IA_FIRST_FIXATION_DUR…¹ IA_FIRST_RUN_DWELL_T…²
<chr> <dbl> <chr> <dbl> <dbl> <dbl>
1 px3 1 RIGHT 0 0 0
2 px3 2 RIGHT 0 0 0
3 px3 3 RIGHT 0 0 0
4 px3 3 RIGHT 0 0 0
5 px3 3 RIGHT 0 0 0
6 px3 3 RIGHT 0 0 0
# ℹ abbreviated names: ¹IA_FIRST_FIXATION_DURATION, ²IA_FIRST_RUN_DWELL_TIME
# ℹ 22 more variables: IA_FIXATION_COUNT <dbl>, IA_ID <dbl>, IA_LABEL <chr>,
# IA_REGRESSION_IN <dbl>, IA_REGRESSION_IN_COUNT <dbl>,
# IA_REGRESSION_OUT <dbl>, IA_REGRESSION_OUT_COUNT <dbl>,
# IA_REGRESSION_PATH_DURATION <dbl>, KeyPress <dbl>, rt <dbl>, bio <chr>,
# critical <chr>, gender <chr>, item_id <dbl>, list <dbl>, match <chr>,
# condition <chr>, name <chr>, name_vital_status <chr>, tense <chr>, …
# A tibble: 6 × 28
px trial eye IA_DWELL_TIME IA_FIRST_FIXATION_DUR…¹ IA_FIRST_RUN_DWELL_T…²
<chr> <dbl> <chr> <dbl> <dbl> <dbl>
1 px3 1 RIGHT 0 0 0
2 px3 2 RIGHT 0 0 0
3 px3 3 RIGHT 0 0 0
4 px3 3 RIGHT 0 0 0
5 px3 3 RIGHT 0 0 0
6 px3 3 RIGHT 0 0 0
# ℹ abbreviated names: ¹IA_FIRST_FIXATION_DURATION, ²IA_FIRST_RUN_DWELL_TIME
# ℹ 22 more variables: IA_FIXATION_COUNT <dbl>, IA_ID <dbl>, IA_LABEL <chr>,
# IA_REGRESSION_IN <dbl>, IA_REGRESSION_IN_COUNT <dbl>,
# IA_REGRESSION_OUT <dbl>, IA_REGRESSION_OUT_COUNT <dbl>,
# IA_REGRESSION_PATH_DURATION <dbl>, KeyPress <dbl>, rt <dbl>, bio <chr>,
# critical <chr>, gender <chr>, item_id <dbl>, list <dbl>, match <chr>,
# condition <chr>, name <chr>, name_vital_status <chr>, tense <chr>, …
head() function# A tibble: 2 × 28
px trial eye IA_DWELL_TIME IA_FIRST_FIXATION_DUR…¹ IA_FIRST_RUN_DWELL_T…²
<chr> <dbl> <chr> <dbl> <dbl> <dbl>
1 px3 1 RIGHT 0 0 0
2 px3 2 RIGHT 0 0 0
# ℹ abbreviated names: ¹IA_FIRST_FIXATION_DURATION, ²IA_FIRST_RUN_DWELL_TIME
# ℹ 22 more variables: IA_FIXATION_COUNT <dbl>, IA_ID <dbl>, IA_LABEL <chr>,
# IA_REGRESSION_IN <dbl>, IA_REGRESSION_IN_COUNT <dbl>,
# IA_REGRESSION_OUT <dbl>, IA_REGRESSION_OUT_COUNT <dbl>,
# IA_REGRESSION_PATH_DURATION <dbl>, KeyPress <dbl>, rt <dbl>, bio <chr>,
# critical <chr>, gender <chr>, item_id <dbl>, list <dbl>, match <chr>,
# condition <chr>, name <chr>, name_vital_status <chr>, tense <chr>, …
head() function taskExercise: head()
n = 2 to some other number and print?head in the Console
df_lifetime as argument; how many rows does it print as default?n = in this function to print some other number of rowstail() function# A tibble: 6 × 28
px trial eye IA_DWELL_TIME IA_FIRST_FIXATION_DUR…¹ IA_FIRST_RUN_DWELL_T…²
<chr> <dbl> <chr> <dbl> <dbl> <dbl>
1 px4 207 LEFT 509 218 509
2 px4 208 LEFT 0 0 0
3 px4 208 LEFT 317 167 317
4 px4 208 LEFT 162 162 162
5 px4 208 LEFT 139 139 139
6 px4 208 LEFT 280 280 280
# ℹ abbreviated names: ¹IA_FIRST_FIXATION_DURATION, ²IA_FIRST_RUN_DWELL_TIME
# ℹ 22 more variables: IA_FIXATION_COUNT <dbl>, IA_ID <dbl>, IA_LABEL <chr>,
# IA_REGRESSION_IN <dbl>, IA_REGRESSION_IN_COUNT <dbl>,
# IA_REGRESSION_OUT <dbl>, IA_REGRESSION_OUT_COUNT <dbl>,
# IA_REGRESSION_PATH_DURATION <dbl>, KeyPress <dbl>, rt <dbl>, bio <chr>,
# critical <chr>, gender <chr>, item_id <dbl>, list <dbl>, match <chr>,
# condition <chr>, name <chr>, name_vital_status <chr>, tense <chr>, …
names() [1] "px" "trial"
[3] "eye" "IA_DWELL_TIME"
[5] "IA_FIRST_FIXATION_DURATION" "IA_FIRST_RUN_DWELL_TIME"
[7] "IA_FIXATION_COUNT" "IA_ID"
[9] "IA_LABEL" "IA_REGRESSION_IN"
[11] "IA_REGRESSION_IN_COUNT" "IA_REGRESSION_OUT"
[13] "IA_REGRESSION_OUT_COUNT" "IA_REGRESSION_PATH_DURATION"
[15] "KeyPress" "rt"
[17] "bio" "critical"
[19] "gender" "item_id"
[21] "list" "match"
[23] "condition" "name"
[25] "name_vital_status" "tense"
[27] "type" "yes_press"
summary() px trial eye IA_DWELL_TIME
Length:4431 Min. : 1.0 Length:4431 Min. : 0.0
Class :character 1st Qu.: 52.5 Class :character 1st Qu.: 0.0
Mode :character Median :104.0 Mode :character Median : 301.0
Mean :105.0 Mean : 587.5
3rd Qu.:157.0 3rd Qu.: 765.5
Max. :208.0 Max. :8968.0
IA_FIRST_FIXATION_DURATION IA_FIRST_RUN_DWELL_TIME IA_FIXATION_COUNT
Min. : 0.0 Min. : 0.0 Min. : 0.000
1st Qu.: 0.0 1st Qu.: 0.0 1st Qu.: 0.000
Median :161.0 Median : 245.0 Median : 2.000
Mean :139.4 Mean : 507.9 Mean : 2.714
3rd Qu.:202.5 3rd Qu.: 586.0 3rd Qu.: 4.000
Max. :775.0 Max. :8968.0 Max. :35.000
IA_ID IA_LABEL IA_REGRESSION_IN IA_REGRESSION_IN_COUNT
Min. :1.000 Length:4431 Min. :0.00000 Min. :0.0000
1st Qu.:1.000 Class :character 1st Qu.:0.00000 1st Qu.:0.0000
Median :2.000 Mode :character Median :0.00000 Median :0.0000
Mean :2.681 Mean :0.09817 Mean :0.1318
3rd Qu.:4.000 3rd Qu.:0.00000 3rd Qu.:0.0000
Max. :6.000 Max. :1.00000 Max. :5.0000
IA_REGRESSION_OUT IA_REGRESSION_OUT_COUNT IA_REGRESSION_PATH_DURATION
Min. :0.00000 Min. :0.00000 Min. : 0.0
1st Qu.:0.00000 1st Qu.:0.00000 1st Qu.: 0.0
Median :0.00000 Median :0.00000 Median : 282.0
Mean :0.08147 Mean :0.09185 Mean : 595.6
3rd Qu.:0.00000 3rd Qu.:0.00000 3rd Qu.: 747.0
Max. :1.00000 Max. :7.00000 Max. :10242.0
KeyPress rt bio critical
Min. :4.000 Min. : 533 Length:4431 Length:4431
1st Qu.:4.000 1st Qu.: 1332 Class :character Class :character
Median :4.000 Median : 1890 Mode :character Mode :character
Mean :4.496 Mean : 2467
3rd Qu.:5.000 3rd Qu.: 2910
Max. :5.000 Max. :15654
gender item_id list match
Length:4431 Min. : 1.00 Min. :14.00 Length:4431
Class :character 1st Qu.: 26.00 1st Qu.:15.00 Class :character
Mode :character Median : 51.00 Median :25.00 Mode :character
Mean : 64.16 Mean :29.45
3rd Qu.: 78.50 3rd Qu.:35.00
Max. :208.00 Max. :45.00
condition name name_vital_status tense
Length:4431 Length:4431 Length:4431 Length:4431
Class :character Class :character Class :character Class :character
Mode :character Mode :character Mode :character Mode :character
type yes_press
Length:4431 Min. :4.000
Class :character 1st Qu.:4.000
Mode :character Median :4.000
Mean :4.499
3rd Qu.:5.000
Max. :5.000
Take some time to explore the dataset.
class() takes as its argument an object or numberSelecting a column
trial
Min. : 1.0
1st Qu.: 52.5
Median :104.0
Mean :105.0
3rd Qu.:157.0
Max. :208.0
trial
Min. : 1.0
1st Qu.: 52.5
Median :104.0
Mean :105.0
3rd Qu.:157.0
Max. :208.0
Min. 1st Qu. Median Mean 3rd Qu. Max.
1.0 52.5 104.0 105.0 157.0 208.0
character classnumeric classyes_press and KeyPress (with 4 or 5)item_id, which ranges from 1:120
item 1 and item 2 has nothing to do with the difference between the numbers 1 and 2
factor classfactor class
factor classdf_lifetime$yes_press to factor
mutate() verb from dplyr
as_factor() from forcats
px trial eye IA_DWELL_TIME
Length:4431 Min. : 1.0 Length:4431 Min. : 0.0
Class :character 1st Qu.: 52.5 Class :character 1st Qu.: 0.0
Mode :character Median :104.0 Mode :character Median : 301.0
Mean :105.0 Mean : 587.5
3rd Qu.:157.0 3rd Qu.: 765.5
Max. :208.0 Max. :8968.0
IA_FIRST_FIXATION_DURATION IA_FIRST_RUN_DWELL_TIME IA_FIXATION_COUNT
Min. : 0.0 Min. : 0.0 Min. : 0.000
1st Qu.: 0.0 1st Qu.: 0.0 1st Qu.: 0.000
Median :161.0 Median : 245.0 Median : 2.000
Mean :139.4 Mean : 507.9 Mean : 2.714
3rd Qu.:202.5 3rd Qu.: 586.0 3rd Qu.: 4.000
Max. :775.0 Max. :8968.0 Max. :35.000
IA_ID IA_LABEL IA_REGRESSION_IN IA_REGRESSION_IN_COUNT
Min. :1.000 Length:4431 Min. :0.00000 Min. :0.0000
1st Qu.:1.000 Class :character 1st Qu.:0.00000 1st Qu.:0.0000
Median :2.000 Mode :character Median :0.00000 Median :0.0000
Mean :2.681 Mean :0.09817 Mean :0.1318
3rd Qu.:4.000 3rd Qu.:0.00000 3rd Qu.:0.0000
Max. :6.000 Max. :1.00000 Max. :5.0000
IA_REGRESSION_OUT IA_REGRESSION_OUT_COUNT IA_REGRESSION_PATH_DURATION
Min. :0.00000 Min. :0.00000 Min. : 0.0
1st Qu.:0.00000 1st Qu.:0.00000 1st Qu.: 0.0
Median :0.00000 Median :0.00000 Median : 282.0
Mean :0.08147 Mean :0.09185 Mean : 595.6
3rd Qu.:0.00000 3rd Qu.:0.00000 3rd Qu.: 747.0
Max. :1.00000 Max. :7.00000 Max. :10242.0
KeyPress rt bio critical
Min. :4.000 Min. : 533 Length:4431 Length:4431
1st Qu.:4.000 1st Qu.: 1332 Class :character Class :character
Median :4.000 Median : 1890 Mode :character Mode :character
Mean :4.496 Mean : 2467
3rd Qu.:5.000 3rd Qu.: 2910
Max. :5.000 Max. :15654
gender item_id list match
Length:4431 Min. : 1.00 Min. :14.00 Length:4431
Class :character 1st Qu.: 26.00 1st Qu.:15.00 Class :character
Mode :character Median : 51.00 Median :25.00 Mode :character
Mean : 64.16 Mean :29.45
3rd Qu.: 78.50 3rd Qu.:35.00
Max. :208.00 Max. :45.00
condition name name_vital_status tense
Length:4431 Length:4431 Length:4431 Length:4431
Class :character Class :character Class :character Class :character
Mode :character Mode :character Mode :character Mode :character
type yes_press
Length:4431 4:2218
Class :character 5:2213
Mode :character
# change ROI & label to factor
df_lifetime %>%
mutate(KeyPress = as_factor(KeyPress),
item_id = as_factor(item_id)) %>%
summary() px trial eye IA_DWELL_TIME
Length:4431 Min. : 1.0 Length:4431 Min. : 0.0
Class :character 1st Qu.: 52.5 Class :character 1st Qu.: 0.0
Mode :character Median :104.0 Mode :character Median : 301.0
Mean :105.0 Mean : 587.5
3rd Qu.:157.0 3rd Qu.: 765.5
Max. :208.0 Max. :8968.0
IA_FIRST_FIXATION_DURATION IA_FIRST_RUN_DWELL_TIME IA_FIXATION_COUNT
Min. : 0.0 Min. : 0.0 Min. : 0.000
1st Qu.: 0.0 1st Qu.: 0.0 1st Qu.: 0.000
Median :161.0 Median : 245.0 Median : 2.000
Mean :139.4 Mean : 507.9 Mean : 2.714
3rd Qu.:202.5 3rd Qu.: 586.0 3rd Qu.: 4.000
Max. :775.0 Max. :8968.0 Max. :35.000
IA_ID IA_LABEL IA_REGRESSION_IN IA_REGRESSION_IN_COUNT
Min. :1.000 Length:4431 Min. :0.00000 Min. :0.0000
1st Qu.:1.000 Class :character 1st Qu.:0.00000 1st Qu.:0.0000
Median :2.000 Mode :character Median :0.00000 Median :0.0000
Mean :2.681 Mean :0.09817 Mean :0.1318
3rd Qu.:4.000 3rd Qu.:0.00000 3rd Qu.:0.0000
Max. :6.000 Max. :1.00000 Max. :5.0000
IA_REGRESSION_OUT IA_REGRESSION_OUT_COUNT IA_REGRESSION_PATH_DURATION KeyPress
Min. :0.00000 Min. :0.00000 Min. : 0.0 4:2234
1st Qu.:0.00000 1st Qu.:0.00000 1st Qu.: 0.0 5:2197
Median :0.00000 Median :0.00000 Median : 282.0
Mean :0.08147 Mean :0.09185 Mean : 595.6
3rd Qu.:0.00000 3rd Qu.:0.00000 3rd Qu.: 747.0
Max. :1.00000 Max. :7.00000 Max. :10242.0
rt bio critical gender
Min. : 533 Length:4431 Length:4431 Length:4431
1st Qu.: 1332 Class :character Class :character Class :character
Median : 1890 Mode :character Mode :character Mode :character
Mean : 2467
3rd Qu.: 2910
Max. :15654
item_id list match condition
2 : 48 Min. :14.00 Length:4431 Length:4431
7 : 48 1st Qu.:15.00 Class :character Class :character
8 : 48 Median :25.00 Mode :character Mode :character
9 : 48 Mean :29.45
10 : 48 3rd Qu.:35.00
12 : 48 Max. :45.00
(Other):4143
name name_vital_status tense type
Length:4431 Length:4431 Length:4431 Length:4431
Class :character Class :character Class :character Class :character
Mode :character Mode :character Mode :character Mode :character
yes_press
Min. :4.000
1st Qu.:4.000
Median :4.000
Mean :4.499
3rd Qu.:5.000
Max. :5.000
Which class should the following variables be (numeric, factor, or character)?:
change them to these class types, and print a summary
save and render the document
Scatterplot
In your Quarto document:
mean(), sd()) + create a boxplot of the variableprint options
eval = FALSE: do not evaluate this chunkinclude = FALSE evaluate this chunk but don’t show it or its resultsecho = FALSE print this chunk codemessage = FALSE/warning = false don’t print warnings or messageserror = TRUE continue rendering document even if there’s an error
error = TRUE for final versions! You want to make sure things work as they shouldor
R version 4.2.3 (2023-03-15)
Platform: aarch64-apple-darwin20 (64-bit)
Running under: macOS Ventura 13.2.1
Matrix products: default
BLAS: /Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/lib/libRblas.0.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/lib/libRlapack.dylib
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] rbbt_0.0.0.9000 beepr_1.3 lubridate_1.9.2 forcats_1.0.0
[5] stringr_1.5.0 dplyr_1.1.1 purrr_1.0.1 readr_2.1.4
[9] tidyr_1.3.0 tibble_3.2.1 ggplot2_3.4.2 tidyverse_2.0.0
[13] here_1.0.1
loaded via a namespace (and not attached):
[1] pillar_1.9.0 compiler_4.2.3 tools_4.2.3 bit_4.0.5
[5] digest_0.6.31 timechange_0.2.0 jsonlite_1.8.4 evaluate_0.20
[9] lifecycle_1.0.3 gtable_0.3.3 pkgconfig_2.0.3 rlang_1.1.0
[13] cli_3.6.1 rstudioapi_0.14 parallel_4.2.3 curl_5.0.0
[17] yaml_2.3.7 xfun_0.38 fastmap_1.1.1 httr_1.4.5
[21] withr_2.5.0 knitr_1.42 fs_1.6.1 generics_0.1.3
[25] vctrs_0.6.1 hms_1.1.3 bit64_4.0.5 rprojroot_2.0.3
[29] grid_4.2.3 tidyselect_1.2.0 glue_1.6.2 R6_2.5.1
[33] fansi_1.0.4 vroom_1.6.1 rmarkdown_2.21 tzdb_0.3.0
[37] magrittr_2.0.3 scales_1.2.1 htmltools_0.5.5 colorspace_2.1-0
[41] utf8_1.2.3 stringi_1.7.12 munsell_0.5.0 crayon_1.5.2
[45] audio_0.1-10